package leetcode.秋招.shopee;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zsy
 * @date ：Created 2021/7/19 14:48
 * @description：
 */
public class 输出杨辉三角的第K行第J列 {
    public static void main(String[] args) {

    }


    @Test
    public void test() {
        Solution solution = new Solution();
        for (int i = 0; i < 10; i++) {
            //System.out.println(solution.getRow(i));
            //System.out.print(" " + solution.getValue(i, 0));
        }
        System.out.println(solution.getRow(3 - 1));
        System.out.println(solution.getValue(3, 2 - 1));
    }


    class Solution {
        public List<Integer> getRow(int rowIndex) {
            List<Integer> list = new ArrayList<>();
            list.add(1);
            for(int i = 0; i < rowIndex; i++) {
                list = getRow0(list);
            }
            return list;
        }

        public int getValue(int rowIndex, int columnIndex) {
            // write code here
            List<Integer> list = new ArrayList<>();
            list.add(1);
            for(int i = 0; i < rowIndex; i++) {
                list = getRow0(list);
            }
            return list.get(columnIndex - 1);
        }

        public List<Integer> getRow0(List<Integer> list) {
            int length = list.size();
            List<Integer> list1 = new ArrayList<Integer>();
            list1.add(1);
            for(int i = 1; i < length; i++) {
                list1.add(list.get(i - 1) + list.get(i));
            }
            list1.add(1);
            return list1;
        }
    }
}
